﻿using System;
using System.Windows;
using System.Windows.Data;

namespace Com.Lancetinc.Evs.WpfTools
{
    public class CornerRadiusToAllConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is not CornerRadius cr)
                return 0;

            foreach (var val in new double[] { cr.TopLeft, cr.TopRight, cr.BottomRight, cr.BottomLeft })
            {
                if (val > 0)
                    return val;
            }

            return 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is not double v)
                return new CornerRadius(0);
            return new CornerRadius(v);
        }
    }
}
